package com.lenin.omena.server;

import javax.jdo.Transaction;

import com.lenin.omena.shared.domain.Address;
import com.lenin.omena.shared.domain.Site;
import com.lenin.omena.shared.domain.User;
import com.lenin.omena.shared.domain.UserInfo;

//@Repository("siteDAO")
public class AddressDAO extends JdoDAO<Long, Address> {

	public AddressDAO() {
		super();
	}
	
	
	public Address saveAddress(Site site, Address detachedAddress) {
		
		
		Transaction tx = pm.currentTransaction();

		Address entity = null;
		
		try
		{
		    tx.begin(); // Start the PM transaction
		    
		    Address address = site.getAddress();
		    address.setAddress(detachedAddress.getAddress());
		    address.setLatitude(detachedAddress.getLatitude());
		    address.setLongitude(detachedAddress.getLongitude());
		    
		    entity = pm.makePersistent(address);

		    tx.commit(); // Commit the PM transaction
		}
		finally
		{
		    if (tx.isActive())
		    {
		        tx.rollback(); // Error occurred so rollback the PM transaction
		    }
		}
		
		return entity;
		
		
	}

	
}
